using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web;
using System.Security.Permissions;

namespace Melis.Chat
{
	[ControlBuilder(typeof(LiteralControlBuilder)), DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DefaultProperty("Text"), Designer("System.Web.UI.Design.WebControls.LiteralDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class Interface : Control
	{
		private string _height = "200px";
		private string _width = "200px";
		private string _userName;


		public Interface()
		{
			_userName = "Guest" + DateTime.Now.Ticks.ToString();
		}

		public string UserName
		{
			get { return _userName; }
			set { _userName = value; }
		}

		protected override void OnLoad(EventArgs e)
		{
			this.Page.ClientScript.RegisterClientScriptResource(typeof(WebResources), WebResources.jsAjax);

			base.OnLoad(e);
		}
		protected override void Render(HtmlTextWriter writer)
		{
			writer.WriteLine("<div id=\"" + this.ClientID + "mlxOut\" name=\"" + this.ClientID + "mlxOut\" style=\"height: " + _height + ";width: " + _width + ";border: solid 1px #000000;\"></div>");
			writer.WriteLine("<div>");
			writer.WriteLine("<input id=\"" + this.ClientID + "mlxText\" name=\"" + this.ClientID + "mlxText\" type=\"text\" style=\"border: solid 1px #000000; width: 170px\" onkeypress=\"return KeyPress(event, '" + this.ClientID + "');\"  />");
			writer.WriteLine("<input id=\"" + this.ClientID + "mlxBtn\" name=\"" + this.ClientID + "mlxBtn\" type=\"button\" style=\"border: solid 1px #000000; width: 30px\" value=\"Invia\" onclick=\"javascript:SendText('" + this.ClientID + "');return false;\" />");
			writer.WriteLine("<input id=\"" + this.ClientID + "mlxUserName\" name=\"" + this.ClientID + "mlxUserName\" type=\"hidden\" value=\"" + _userName + "\" />");
			writer.WriteLine("</div>");
			writer.WriteLine("<script type=\"text/javascript\">");
			writer.WriteLine("setTimeout(\"Refresh(\'" + this.ClientID + "\')\", 5000);");
			writer.WriteLine("Join(\'" + this.ClientID + "\');");
			writer.WriteLine("</script>");
		}
	}
}
